home *** CD-ROM | disk | FTP | other *** search
/ The Game Master (3rd Edition) / The Game Master 3rd edition.iso / files / windonal / fuzzgen / fuzzgen.doc < prev    next >
Text File  |  1992-06-26  |  21KB  |  470 lines

  1.  
  2.  
  3.  
  4.                                F U Z Z G E N
  5.  
  6.                       Fuzzy Logic Source Code Generator
  7.  
  8.                            Evaluation Version 1.0
  9.  
  10.  
  11.  
  12.                             U S E R    G U I D E 
  13.  
  14.  
  15.  
  16.       INTRODUCTION:
  17.  
  18.       As programmers, many of us have heard the terms NEURAL NETWORKS
  19.       and FUZZY LOGIC bandied about over the last couple of years. The 
  20.       odd thing is that very few of us that write code on a daily basis
  21.       really have a handle on what these things mean. 
  22.  
  23.       Fuzzy Logic is a decision making method for computers. It has 
  24.       taken many years for the merits of Fuzzy Logic to become clear. 
  25.       One of the reasons is the name: people hear "Fuzzy Logic" and 
  26.       immediately assume that it is imprecise. Actually, it is the
  27.       other way around -- Fuzzy Logic allows FOR imprecision in the
  28.       input in making a precise decision. 
  29.  
  30.       The idea that Fuzzy Logic is suited only to microcontroller
  31.       applications such as flow controllers and such is also quite
  32.       misleading. It is suitable for a wide variety of applications.
  33.  
  34.       Fuzzy Logic also allows for perspective to change without having
  35.       to completely recode massive programs. For instance, if you have
  36.       a program like a battle simulation that takes factors such as
  37.       the effect of heat into account on the troops, the perspective
  38.       of HOT changes depending on the origin of the troops. Swedish or
  39.       Russian troops may see 80 degrees F as hot, whereas troops from
  40.       countries nearer the equator see 100 degrees as hot and 80
  41.       degrees as mild. Being able to make this decision in a "Fuzzy"
  42.       manner means that you can read in the control variables as needed
  43.       and still guarantee the integrity of a decision made by the
  44.       program. 
  45.  
  46.       FuzzGen is a program intended to introduce you to Fuzzy concepts
  47.       and allow you to create Fuzzy decision sets for your own programs.
  48.       It allows you to graphically model the decision process to aid in
  49.       visualising a decision. It also produces source code in PASCAL,
  50.       BASIC, or C so that you can incorporate Fuzzy decision making in
  51.       your programs. It is intended to save time so that you do not need
  52.       to keep coding IF - THEN - ELSE blocks to make decisions in your
  53.       programs. Essentially, FuzzGen is a CASE tool that is additionally
  54.       educational in that it will introduce many of you to new concepts.
  55.  
  56.       
  57.       BASIC CONCEPTS:
  58.  
  59.       Fuzzy Logic is a little like the "new math" some of us were taught
  60.       (starting in the late 60's and early 70's in most districts) in
  61.       school. Fuzzy Logic uses the concept of SETS and membership. What
  62.       this means is that a data point is seen as either being a set
  63.       member or not, and more importantly, HOW MUCH of a member. Using 
  64.       triangular and trapezoidal shapes to model data allows you to plot
  65.       a data point on a slope. Rather than exclusively dealing with YES/NO,
  66.       you can deal with "65%" or "32%" membership. In essence, you can 
  67.       say that data point X is a Y% member of data set Z. This allows you
  68.       to have much more control over input data variance, as we can 
  69.       immediately see exactly where input data lies.
  70.  
  71.       This allows for a different way to code than what you're used to.
  72.       (By the way, we'll be using code fragments done in C to illustrate
  73.       points as we go along.) For instance, here's how you may code for
  74.       a variable input in standard ways:
  75.  
  76.       if(INPUT_DATA <= .1) 
  77.          we_do_this();
  78.       else if(INPUT_DATA > .1 && INPUT_DATA <= .2) 
  79.          we_do_that();
  80.       else if(INPUT_DATA > .2 && INPUT_DATA <= .3)
  81.          do_something_else();
  82.       // AND SO ON...
  83.  
  84.       Fuzzy Logic tends to compartmentalise things. Therefore, instead 
  85.       of a big IF-ELSE construct, you could use the following:
  86.  
  87.       int i, SetNumber;
  88.       double testval, setpctg = 0;
  89.  
  90.       for(i = 0; i < NumOfSets; i++){          // loop
  91.           testval = InSet(i, INPUT_DATA);      // is data in the set?
  92.           if(testval > setpctg){               // if so,
  93.              setpctg = testval;                // reset high pctg marker 
  94.              SetNumber = i;                    // and record which set.      
  95.           }  
  96.       }
  97.       do_whatever_we_need_done(SetNumber);
  98.       
  99.  
  100.       What the above code does is record the set with the highest 
  101.       membership percentage so that we have a variable that shows what
  102.       set the data is in and also what action to take. At first blush,
  103.       this may not seem any better than the "old" way using the large
  104.       IF-ELSE construct. However, if you stop and think about it, you
  105.       have more control with the second method. Sure, we could change
  106.       the test points to variables in both cases, but the second method
  107.       does not need to be recompiled if you change your mind about the 
  108.       number of tests to make.  This is provided by variable NumOfSets.
  109.       Now, using the Fuzzy method, you can read your variable list in
  110.       PLUS you can read in how many tests to take. Sure, you could do
  111.       this yourself with IF-ELSE constructs, but this is easier. 
  112.  
  113.       The next step is to make it simpler to model a decision so that
  114.       it is simple to see what is happening.       
  115.             
  116.  
  117.       GRAPHICS AND DECISION VISUALISATION:
  118.  
  119.       FuzzGen uses a 2 axis graph to allow you to see data sets and 
  120.       their relationships. The Y axis of the graph is used to show
  121.       percentage and ranges from 0 - 100. The X axis is used to show
  122.       the ordinal range of input data values. See figure 1.
  123.  
  124.        
  125.        | 100
  126.        |
  127.        |
  128.        | <---------------- Percentage       
  129.        |
  130.        |                       Ordinal Data
  131.        |                            |
  132.        |                            |
  133.        |_0_________________________________________________________    
  134.             
  135.        4                                                          20
  136.        
  137.                -=-=-=-=-=-= 4-20 ma current input =-=-=-=-=-
  138.  
  139.                                   fig 1
  140.  
  141.  
  142.        Also, to be able to properly plot data values into sets, we use
  143.        shapes to classify them. Common shapes (supported by FuzzGen) are
  144.        Triangular, Trapezoidal, and Square (Boolean.) There is infinite
  145.        variety possible using the Triangular and Trapezoidal shapes.
  146.  
  147.        As an example, we'll now graph out a simple Fuzzy Logic demo that
  148.        shows how to use the graphics and shapes to allow a change of 
  149.        perspective. The subject is temperature as seen by a Polar Bear 
  150.        and as seen by someone's grandmother.
  151.  
  152.              ______________________60            82_________ 
  153.        100  |                       \            /          |
  154.             |                        \          /           |
  155.           P |                         \        /            |
  156.           C |                          \      /             |
  157.           T |    C O L D                \    /  H O T       |
  158.           G |                            \  /               |
  159.             |                             \/                |
  160.             |                             /\                |
  161.          0  |____________________________/__\_______________|
  162.             0                           65  70             100
  163.  
  164.              -=-=-=-=TEMPERATURE AS SEEN BY GRANDMA =-=-=-=-
  165.                                  
  166.                                   fig 2                         
  167.        
  168.                       
  169.        So, in this scenario, if you wanted to find out what Grandma
  170.        would think of, say, 62 degrees, you would plot along the X
  171.        axis to 62 degrees and find out where the decision shape 
  172.        intersected the decision shapes at. In this case here, Grandma
  173.        would see 62 degrees as 75% COLD and not HOT at all. (It didn't
  174.        intersect the HOT decision at all.) The COLD decision set uses
  175.        a Trapezoidal shape: anything from 0 - 60 is seen as 100% COLD,
  176.        and at 60 degrees it starts tapering down to 70. HOT also uses 
  177.        a trapezoidal shape. 
  178.  
  179.  
  180.                _____10           34___________________________
  181.          100  |     \            /                            |
  182.               |      \          /                             |
  183.             P |       \        /                              |
  184.             C |        \      /                               |
  185.             T | MILD    \    /           H O T                |
  186.             G |          \  /                                 |
  187.               |           \/                                  |
  188.               |           /\                                  | 
  189.            0  |__________/__\_________________________________|
  190.               0         20  25                               100
  191.  
  192.              -=-=-=-=TEMPERATURE AS SEEN BY A POLAR BEAR =-=-=-=-  
  193.                          
  194.                                     fig 3
  195.  
  196.        On the other hand, we have in this scenario the EXACT SAME
  197.        decision shapes used, but now we see the SAME RANGE of the
  198.        temperature as seen by a Polar Bear. Note that the bear sees
  199.        anything under 10 degrees as MILD, and anything above this as
  200.        getting warmer. Downright HOT starts at 34 degrees.
  201.          
  202.        In these two cases we see the same data being looked at by use
  203.        of Fuzzy Logic decisions to base COLD or HOT on the perspective
  204.        of the viewer. While this is a very simple example, it should 
  205.        serve to explain the basic FuzzGen modeling of Fuzzy Logic.
  206.  
  207.           
  208.        USING FUZZGEN:
  209.  
  210.        As the program starts up, it will allow you to either get Help,
  211.        Open a data file, or start a New file. Once you get a filename 
  212.        started, you are allowed to SETUP the GRAPH. 
  213.  
  214.  
  215.        STEP 1: SET UP THE GRAPH BASICS
  216.  
  217.        In the graph setup, you may want to put a label on the X axis 
  218.        so that viewing of the graph is a little clearer. You can also 
  219.        optionally put tickmarks and Major Tickmarks along the X axis 
  220.        so that it is easier to see where a decision is intersected. 
  221.        You'll also need to specify the unit range of input data, which 
  222.        is required. For instance, if your input data is in degrees 
  223.        Farenheight, your range may be (like our example) 0 - 100. On 
  224.        the other hand, you may want to create code that reads a hardware
  225.        current loop device from 4 - 20 milliamps. In other words, the
  226.        range used is up to you and your application. The last thing to 
  227.        do is tell FuzzGen how many decisions it will need to work with.
  228.        You may use up to 10 in this evaluation version.
  229.        
  230.        All of these settings can be changed later, such as changing your 
  231.        mind about how many decisions to work with and do on.
  232.  
  233.       
  234.        STEP 2: ADD DECISION SHAPES
  235.  
  236.        You'll need to access SETUP | DATA SETS. This window allows you
  237.        to choose a general shape by clicking the associated option 
  238.        button. You can "fine-tune" the triangular and trapezoidal shapes
  239.        by clicking the picture underneath the option button. Each click
  240.        will cause the picture to cycle through the possible shapes.
  241.  
  242.        As you click the option buttons denoting shape, the data input
  243.        boxes denoting major hinge points of the shape (i.e. endpoints
  244.        and apexes) will change to reflect the number of inputs this 
  245.        shape will need: Boolean - 2, Trapezoidal - 4, Triangular - 3.
  246.        These data input boxes allow for full double-precision data, so
  247.        you're not limited to integer based decision-making.
  248.  
  249.        Once you decide on a basic shape, you can enter the data. FuzzGen
  250.        may sometimes disallow your input and warn you to that effect. If
  251.        this happens, look at the basic shape picture to see if it allows
  252.        you to do what you want. In general, the shapes that do not have
  253.        a straight side have the ability to place the apex hinge points 
  254.        anywhere you want.
  255.  
  256.        Next, you should pick a "Tag colour" by clicking the little box
  257.        with a colour in it. This allows you to pick a colour so that 
  258.        when the graph is drawn it is easier to associate the particular
  259.        decision shape with a colour. 
  260.  
  261.        Once these items are in order, you should click the RECORD button
  262.        to record the input. You can then select a new decision to enter
  263.        or edit data for by clicking the LEFT-RIGHT buttons in the lower
  264.        right. Above the buttons is a label showing you what decision 
  265.        you are working on (numbered) such as "1 of 4."
  266.  
  267.        At any time, you can access a SHAPE HELP by clicking the HELP 
  268.        button. The SHAPE HELP window shows you the basics of working
  269.        with the shapes. As you get more accustomed to working with 
  270.        FuzzGen, you'll rely on this a little less.
  271.  
  272.        Once you have essentially defined the decsion shapes, we can then
  273.        proceed to the next step.
  274.  
  275.        STEP 3: MODELING
  276.  
  277.        You should now exit from the SETUP DATA SETS window by clicking
  278.        the CANCEL button. On the main FuzzGen window, click the APPLY
  279.        button. Your graph and basic data shapes are shown. You may at
  280.        this time elect to go back to SETUP GRAPH or SETUP DATA SETS to
  281.        fine tune your model. In this sense, FuzzGen is interactive in
  282.        that you can make an adjustment and come back to click the APPLY
  283.        button to see what the change looks like.
  284.  
  285.        STEP 4: GENERATE SOURCE CODE
  286.  
  287.        The LANGUAGE menu allows you to select a source language to use
  288.        by clicking the language of choice so that it becomes "checked."
  289.  
  290.        If you are satisfied that your application is correctly done (i.e.
  291.        the graph seems to reflect what you're after) and the language
  292.        source is correct, go back to the LANGUAGE menu and select the
  293.        MAKE CODE menu item. This will output a file with the appropriate
  294.        extension added to the name of your data file. For example, if
  295.        you are working with filename DUMMY, here's the source files that
  296.        would be generated depending on your language of choice:
  297.  
  298.        C ------- DUMMY.C
  299.        PASCAL -- DUMMY.PAS
  300.        BASIC --- DUMMY.BAS
  301.  
  302.        Unless you have any second thoughts about the decision modeling,
  303.        you are pretty much done with FuzzGen at this point. You should
  304.        SAVE the data file you are working with for later recall. In the
  305.        FILE menu, select SAVE or SAVE AS. SAVE AS will ask you for a new
  306.        name to save under (other than the one you used). It will save in
  307.        the current data file directory.
  308.  
  309.  
  310.        
  311.        UNDERSTANDING FUZZGEN SOURCE CODE:
  312.  
  313.        Essentially, the code example we used earlier was idealised so
  314.        that you could see how highly optimised Fuzzy code would work. 
  315.        FuzzGen code is slightly different in that we don't know what 
  316.        you'll want to do to optimise it. FuzzGen output source code
  317.        is fully commented such that you should be able to be able to 
  318.        read it without difficulty. We think that you'll want code you 
  319.        can read cleanly rather than highly optimised code that is more
  320.        difficult to decipher.
  321.  
  322.         As such, here's a short description of what a typical source
  323.         file would look like:
  324.  
  325.         It starts out with a series of constants, which are basically 
  326.         the hinge points of the different decision sets. It uses a 
  327.         coding for the names so that you can tell what decision uses
  328.         what constants. Here's an example:
  329.  
  330.         d1low = decision #1, left (low) endpoint
  331.         d1hi  = decision #1, right (high) endpoint
  332.         ap1l  = APEX #1 LEFT = decision #1 left apex
  333.  
  334.         So in a C source output, it would use #defines to set up the
  335.         initial constants:
  336.  
  337.         #define d1low 0
  338.         #define d1hi  20
  339.         etc...
  340.  
  341.         The constant declaration is followed by the source for each of
  342.         the decisions. They are all named decision-n and you pass the 
  343.         inputs (including the data to test) as part of the parameter 
  344.         list. In C:
  345.  
  346.         double Decision1(double TESTDATA, double leftend, 
  347.                          double leftapex, double rightapex,
  348.                          double rightend)
  349.  
  350.  
  351.         For immediate implementation, you'd simply feed a decision with
  352.         the previously defined constants as follows:
  353.  
  354.         double percentage;
  355.  
  356.         percentage = Decision1( DATA, d1low, ap1l, ap1r, d1hi);
  357.  
  358.         This allows you to test each decision independantly.
  359.  
  360.         Our recommendation is that once you're satisfied that the 
  361.         routines work as you want, that you combine them into 1 single
  362.         function as follows:
  363.  
  364.         double FuzzDecision( int DecisionNum, double TestData)
  365.         {
  366.             switch (DecisionNum){
  367.                case 1:
  368.                   BODY OF FUZZGEN DECISION 1 CODE
  369.                case 2:
  370.                   BODY OF FUZZGEN DECISION 2 CODE
  371.  
  372.                ....
  373.  
  374.         }
  375.  
  376.         
  377.         This will allow you to make your decision loop much faster as
  378.         in the example code we had at the beginning of this guide.
  379.  
  380.        
  381.        FUZZGEN DISTRIBUTION:
  382.        
  383.        FuzzGen evaluation version 1.0 is a program that will hopefully
  384.        give you enough of a taste of Fuzzy programming that you'll want
  385.        to give serious consideration to ordering FuzzGen II, which is 
  386.        the enhanced retail version of this product. 
  387.  
  388.        FuzzGen II Features:
  389.  
  390.        * Printing! You can print graphics copies of your decision logic
  391.          to aid in documenting programs.
  392.        * Notes File to attach to the decision logic so that you can
  393.          document the entire decision process, assumptions, etc.
  394.        * More decision sets for those ultra-tough projects.
  395.        * Printed documentation with some more tricks, techniques and 
  396.          hints.
  397.   
  398.        FuzzGen is a shareware product, meaning that it has been released
  399.        in a functional format for BBS and disk vendor distribution. It is
  400.        as much of an advertising ploy for Alston Software Labs as much as
  401.        it is useful in and of itself. 
  402.  
  403.  
  404.  
  405.        LEGAL STUFF:
  406.  
  407.        Shareware distribution sometimes is misunderstood. For instance,
  408.        FuzzGen is NOT public domain. It is a copyrighted product wholly
  409.        owned by Alston Software Labs, and licensees (as in standard retail
  410.        software) may use FuzzGen to create source code. Although we do not
  411.        charge any sort of royalty license to use FuzzGen generated source
  412.        code in your programs, you are strictly forbidden to use Fuzzgen 
  413.        code in your programs if you haven't paid for the product. Sorry,
  414.        but any money you paid to get a copy of this program from a vendor
  415.        or other source did not give you any rights to FuzzGen. 
  416.  
  417.         
  418.  
  419.        INDUSTRY STANDARD DISCLAIMER:
  420.  
  421.        FuzzGen evaluation version 1.0 is supplied as-is with no warranty
  422.        whatsoever with regard to merchanability or fitness for purpose.
  423.        Alston Software Labs assumes no responsibility for any consequenses
  424.        of use or misuse of this program.
  425.  
  426.        
  427.  
  428.        HOW TO ORDER:
  429.  
  430.        Product purchase comes in 2 forms: You may elect to "register" 
  431.        FuzzGen as-is for $15, at which point we'll send you a fully
  432.        licensed copy of FuzzGen minus the "Evaluation Copy" tags present
  433.        in this copy. For $25, you may purchase FuzzGen II, which contains
  434.        the added features outlined above. Either payment method will 
  435.        license you to be a registered user with rights to use the source
  436.        code produced by FuzzGen (or FuzzGen II) in your programs without
  437.        any royalty.
  438.  
  439.        Please use WINDOWS NOTEPAD or a similar editor to open ORDER.FRM
  440.        to be able to print the order form / invoice. You'll need to call
  441.        or Fax us for Site License information.
  442.  
  443.  
  444.  
  445.        IN CLOSING:
  446.  
  447.        We sincerely hope you'll be able to learn something from FuzzGen,
  448.        even if you don't order it. We encourage you to pass this product
  449.        on to associates, employees, and other interested parties. 
  450.        (providing, of course, that you charge no fee for it.)    
  451.  
  452.        If you have suggestions for improvement of FuzzGen, we'd sure like
  453.        to hear from you. Our aim is to produce a truly useful Fuzzy Logic
  454.        generator at the lowest possible end-user cost, and we're always
  455.        looking for ways to improve our product line. Speaking of product
  456.        lines, you can see what other ASL products are available by 
  457.        browsing the CATALOG.DOC file using NOTEPAD or a similar tool. 
  458.        
  459.  
  460.        Alston Software Labs
  461.        1320 Standiford Ave #242
  462.        Modesto CA 95350  USA
  463.        
  464.        Phone (209) 522 - 8666
  465.        FAX   (209) 522 - 8666
  466.          
  467.                 
  468.  
  469.         
  470.